<?php
/**
 * @todo i want to move the content filtering back to a content renderer, so it is filtering
 * the content independently
 */
class DigCms_View_Filter_ContentFilter
{
    public $tag;
    public $view;
    protected $_selfClosing = true;

    public function filter($content)
    {
        $this->view = Zend_Layout::getMvcInstance()->getView();
        $pattern = '/<dig:' . $this->tag . '([^>]*\/>)?(.*dig:' . $this->tag . '>)?/';
        $content = preg_replace_callback($pattern, array($this, '_callback'), $content);
        return $content;
    }

    public function getAttributes($element)
    {
        $xml = @simplexml_load_string($element);
        if ($xml) {
            foreach ($xml->attributes() as $key => $value) {
                $attr[$key] = (string)$value;
            }
            return $attr;
        } else {
            return null;
        }
    }
}

